var viz = {};
eval(loadFile("main/src/viz.js"));
eval(loadFile("main/src/viz.sequenceDiagram.js"));

var screen;
var graphics;

testCases(test,
    function setUp() {
        screen = {
            frameAssets : [],
            coordinates : {},
            addFrameAsset : function (frameAsset) {
                this.frameAssets.push(frameAsset);
            },
            placeFrameAsset : function (frameAsset) {
                this.frameAssets.push(frameAsset);
                this.coordinates[frameAsset.id] = {
                    after : function (previousFrameAsset) {
                        this.previousFrameAsset = previousFrameAsset;
                    }
                };
                return this.coordinates[frameAsset.id];
            }
        };
        graphics = {};
    },

    function shouldBuildFrameAssetsFromMessageTransferEvent() {
        var slide = viz.sequenceDiagram.messageTransfer(screen, {
            sender : "wave.bedroom",
            receiver : "wave.wonderland",
            message : "message"
        });

        assert.that(screen.frameAssets.length, eq(4));

        var notDefined;
        var background = screen.frameAssets[0];
        assert.that(background.id, eq("background"));
        assert.that(screen.coordinates[background.id], eq(notDefined));

        var sender = screen.frameAssets[1];
        var senderCoordinate = screen.coordinates[sender.id];
        assert.that(sender.id, eq("p:wave.bedroom"));
        assert.that(senderCoordinate.previousFrameAsset, eq(notDefined));

        var message = screen.frameAssets[2];
        var messageCoordinate = screen.coordinates[message.id];
        assert.that(message.id, eq("m:wave.bedroom->wave.wonderland"));
        assert.that(messageCoordinate.previousFrameAsset, eq(sender));

        var receiver = screen.frameAssets[3];
        var receiverCoordinate = screen.coordinates[receiver.id];
        assert.that(receiver.id, eq("p:wave.wonderland"));
        assert.that(receiverCoordinate.previousFrameAsset, eq(message));
    },

    function shouldUpdateSlideToProjectBackgroundForFirstFrame() {
        var slide = viz.sequenceDiagram.messageTransfer(screen, {
            sender : "wave.bedroom",
            receiver : "wave.wonderland"
        });

        slide.firstFrame();

        graphics.background = assert.functionThatMustBeCalled("background", function (gray, alpha) {
            assert.that(gray, eq(0));
            assert.that(alpha, eq(96));
        });
        screen.frameAssets[0].draw(graphics);
    }
);